package br.edu.ufcg.lsd.wbis.control.util;

import br.edu.ufcg.lsd.wbis.control.exception.BusinessValidationException;
import br.edu.ufcg.lsd.wbis.control.exception.ErrorType;

/**
 * This class congregates methods for validating parameters.
 * 
 * @author Renato Miceli
 */
public class AbstractValidator {

	/**
	 * Validates whether the given string is either <code>null</code> or blank
	 * (that is, made only of white spaces -- ASCII character 32). In case it
	 * is, the string is considered to be invalid.
	 * 
	 * @param string
	 *            the string to be validated
	 * @throws BusinessValidationException
	 *             if the string is invalid
	 */
	public static void validateNotNullNorBlank(String string) throws BusinessValidationException {
		if (string == null) {
			throw new BusinessValidationException(ErrorType.NULL_VALUE);
		}
		if (string.trim().isEmpty()) {
			throw new BusinessValidationException(ErrorType.BLANK_VALUE);
		}
	}

}
